package cn.zhage.aimin.auth1.service.impl;

import cn.zhage.aimin.auth1.dto.UserDTO;
import cn.zhage.aimin.auth1.entity.Address;
import cn.zhage.aimin.auth1.entity.User;
import cn.zhage.aimin.auth1.mapper.UserMapper;
import cn.zhage.aimin.auth1.service.UserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

/*
 *
 * @author 渣哥
 */
@Service
@RequiredArgsConstructor
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    private final UserMapper userMapper;

    @Override
    public  List<UserDTO> getUserListJoinAddress(int userId) {
        MPJLambdaWrapper<User> wrapper = new MPJLambdaWrapper<User>()
                .selectAll(User.class)//查询user表全部字段
                .select(Address::getCity, Address::getAddress)
                .leftJoin(Address.class, Address::getUserId, User::getId);

        return userMapper.selectJoinList(UserDTO.class, wrapper);
    }
}
